package com.aaa.custom.service.cart;

import com.aaa.custom.dao.cart.CartDao;
import com.aaa.entity.cart_order.kwc.Cart;
import com.aaa.entity.cart_order.kwc.CartList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * fileName:CartServiceImpl
 * description:
 * author:xxx
 * createTime:2020/2/14 13:45
 * version:1.0.0
 */
@Service
public class CartServiceImpl implements CartService{
    @Autowired
    private CartDao cartDao;
    @Override
    public List<CartList> getCartById(long member_id,long shop_id) {
        return cartDao.getCartById(member_id,shop_id);
    }

    @Override
    public int deleteAll(long member_id, long shop_id) {
        return cartDao.deleteAll(member_id,shop_id);
    }

    @Override
    public int addCart(CartList cart) {
        List<CartList> cartLists = ExisProduct(cart.getMember_id(), cart.getShop_id(), cart.getProduct().getProduct_id());
        if ( cartLists.size()>0){
           return cartDao.updateNum(cart.getMember_id(), cart.getShop_id(), cart.getProduct().getProduct_id());
        }else {
            return cartDao.addCart(cart);
        }


    }

    @Override
    public  List<CartList> ExisProduct(long member_id, long shop_id, long product_id) {
        return cartDao.ExisProduct(member_id,shop_id,product_id);
    }

    @Override
    public int updateNum(long member_id, long shop_id, long product_id) {
        return cartDao.updateNum(member_id,shop_id,product_id);
    }

    @Override
    public int subtractCart(CartList cart) {

        return cartDao.subtractCart(cart);
    }
}
